<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>权限管理信息</title>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css"></link>
<link rel="stylesheet" type="text/css" href="../ext/resources/css/xtheme-slate.css"></link>
<script src="../ext/adapter/ext/ext-base.js"></script>
<script src="../ext/ext-all.js"></script>
<script src="../ext/src/locale/ext-lang-zh_CN.js"></script>	
<script type="text/javascript">
			Ext.onReady(function(){
				Ext.Ajax.on('requestcomplete',checkUserSessionStatus, this);      
				function checkUserSessionStatus(conn,response,options){      
				    if(response.getResponseHeader('sessionstatus')){      
				    	parent.location.href='/xdj/index.jsp';   
				    }      
				}  
				//Ext.BLANK_IMAGE_URL='ext/resources/images/default/s.gif';
				var rolenode;
				var  tree2;
				//var roleNode;
				var ids = "";
				var treeloader = new Ext.tree.TreeLoader({   // dataUrl : 'tree.jsp'//这里可以不需要指定URL，在加载前事件响应里面设置 
            		
				});  
				var rootnode = new Ext.tree.AsyncTreeNode({  // 异步加载根节点 
					id : '-1',  
					text : ''
				});  
				rolenode = rootnode;
				
				var tree=new Ext.tree.TreePanel({
					el : 'tree',// 将树形添加到一个指定的div中,非常重要！  
					border:false,
					region : 'west',  
					//title : '功能菜单',  
					lines:true, //线段
					width : 300, 
					height:window.screen.height,
					split : true, 
					frame : true,// 美化界面    
					enableDD : false,// 是否支持拖拽效果  
					containerScroll : true,// 是否支持滚动条  
					rootVisible : false, // 是否隐藏根节点,很多情况下，我们选择隐藏根节点增加美观性  
					animate : true, // 动画效果  
					root : rootnode,
					loader : treeloader ,
					listeners : {
						'beforeload' : function(node) {
							treeloader.dataUrl = "role_loadtree";
						},
						'click' : function(node) {
							 //roleNode=node.id;
							rolenode = node;
							
							rootnode2.reload(function(node) {
								//rootnode2.expand(true);
					        });
							rootnode2.expand(true);
						}
					}
					
				// 树加载  
				});
				tree.render();  // 渲染树形 
				
				var treeloader2 = new Ext.tree.TreeLoader({});
				var rootnode2 = new Ext.tree.AsyncTreeNode({  // 异步加载根节点 
					id : '0',  
					text : '大坝电厂',
					leaf:true
				});	
				 tree2 = new Ext.tree.TreePanel({
						el:'tree2',
						//height:500,
						split : true, 
						frame : true,// 美化界面    
						enableDD : false,// 是否支持拖拽效果  
					//	autoScroll : true,
					//	containerScroll : true,// 是否支持滚动条  
						rootVisible : false, // 是否隐藏根节点,很多情况下，我们选择隐藏根节点增加美观性  
						//animate : true, // 动画效果  
						root : rootnode2,
						loader:treeloader2,
						listeners : {
							'beforeload' : function(node) {
								treeloader2.dataUrl = "role_loadPrivilege?funcParentID=parentID_" +node.id+"_EQ&roleID="+rolenode.id;
							}
						}
					});
					tree2.render();
				
			
				
				 w= new Ext.Viewport({  
					layout : 'border', // 使用border布局  
					items:[{
						region:'west',
						border:false,
						width:200,
						height:window.screen.height,
						layout:'vbox',
						items:[tree]
					},{						
						region:'center',
						border:false,
						autoScroll : true,
						//containerScroll : true,
						//collapsible:true,
						height:window.screen.height,
						items:[tree2],
						tbar: [{
							height:25,
							text:'保存',disabled:true,id:'cSaveRoleFuncBox',
							handler:function(node){
							//var	oSelMode    = tree2.getSelectionModel();
							var	oRecords    = tree2.getChecked();
							Ext.each(oRecords, function(node){
								//alert(node.id);
								ids += node.id+",";
							});
								ids = ids.substring(0,ids.length);
								//alert(ids);
								//alert(roleNode);
							Ext.Ajax.request({
									url:'role_setPrivilege',
									params:{
										funcIDs:ids,
										roleID:rolenode.id
									},
									success:function(){
										alert("保存成功");
									}
							});
							}
						}]
					}],
					listeners:{
						'beforerender' : function(cmp) {
							// set role
							var store=new Ext.data.JsonStore({
								url: '../system/role_loadFunc?funcCode=ControlRoleFunc',
								autoLoad : true,
								fields: ["functioncode"]
							});
							store.load({
							    callback: function(records, options, success){
							    	var i=0;
							    	for(; i<records.length; i++) {
							    		var id = records[i].get("functioncode");
							    		//alert('d'+Ext.getCmp('56').text);
							    		if(Ext.getCmp(id)!=null) {
							    			Ext.getCmp(id).setDisabled(false);
							    		}
							        }
							    },
							    scope: store
							});
						}
					}
				 }); 
				 
			});
		</script> 
</head>
<body>
<div id="tree" ></div>
<div id="tree2"></div>
</body>
</html>